from fastapi import FastAPI
from langchain_core.prompts import ChatPromptTemplate
from langchain_community.chat_models import ChatZhipuAI
from langserve import add_routes

from langchain_core.output_parsers import StrOutputParser

app = FastAPI(
    title="LangServe Server",
    version="1.0",
    description="A Simple api Server using LangChain"
)

model = ChatZhipuAI(model="glm-4-plus", temprature=0.5)

prompts = ChatPromptTemplate.from_messages([
    ('system', '请用{language}翻译下面的内容'),
    ('human', '{content}')
])

parser = StrOutputParser()

add_routes(
    app,
    prompts | model | parser,
    path="/chat"
)

if __name__ == '__main__':

    import uvicorn
    uvicorn.run(app, host="localhost", port=8000)
